﻿function marksure() {
    return confirm("删除后不可恢复，确认删除吗？");
}


function serializeForm(container, selector) {
    var seriStr = "";
    $(container).find(selector).each(function () {
        var name = $(this).attr("name");
        var val = $(this).val();
        switch (this.tagName) {
            case "SPAN":
                val = $(this).text();
                break;
            case "SELECT":
                val = $(this).val();
                break;
            case "INPUT":
                switch ($(this).attr("type")) {
                    case "text":
                    case "hidden":
                    case "password":
                        val = $(this).val();
                        break;
                    case "checkbox":
                        if (this.checked == true) {
                            val = $(this).val();
                        }
                        break;
                    case "radio":
                        if (this.checked == true) {
                            val = $(this).val();
                        }
                        break;
                    default:
                        val = $(this).val();
                        break;
                }
                break;
            default:
                val = $(this).text();
                break;
        }
        seriStr += name + "=" + val + "&";
    })
    if (seriStr.length > 0) {
        seriStr = seriStr.substr(0, seriStr.length - 1);
    }
    return seriStr;
}


//model模拟alert弹出框
function bsAlert(msg) {
    if ($("#bsAlert").length == 0) {
        var alertHtml = "<div class=\"modal fade\" id='bsAlert' tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"mySmallModalLabel\"><div class=\"modal-dialog modal-sm\"><div class=\"modal-content\"><div class=\"modal-header\"><h4 class=\"modal-title\">系统提示</h4></div>";
        alertHtml += " <div class=\"modal-body\">" + msg + "</div><div class=\"modal-footer\"><button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">确定</button></div></div></div></div>";
        $("body").append(alertHtml);
        $("#bsAlert").modal("show");
    }
    else {
        $("#bsAlert").find(".modal-body").text(msg);
        $("#bsAlert").modal("show");
    }
}

//model模拟confirm弹出框
function bsConfirm(msg, fun) {
    if ($("#bsConfirm").length > 0) {
        $("#bsConfirm").undelegate("#bsConfirmYesBtn");
        $("#bsConfirm").remove();
    }
    var confirmHtml = "<div class=\"modal fade\" id='bsConfirm' tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"mySmallModalLabel\"><div class=\"modal-dialog modal-sm\"><div class=\"modal-content\"><div class=\"modal-header\"><h4 class=\"modal-title\">系统提示</h4></div>";
    confirmHtml += " <div class=\"modal-body\">" + msg + "</div><div class=\"modal-footer\">";
    confirmHtml += "<button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\">取消</button>";
    confirmHtml += "<button type=\"button\" id='bsConfirmYesBtn' class=\"btn btn-primary\">确定</button></div></div></div></div>"
    $("body").append(confirmHtml);
    $("#bsConfirm").modal("show");

    $("#bsConfirm").delegate("#bsConfirmYesBtn", "click", function () {
        if (typeof (fun) == "function") {
            fun();
        }
        $("#bsConfirm").modal("hide");
    })
}

function ConvertTime(date) {
    var da = new Date(parseInt(date.replace("/Date(", "").replace(")/", "").split("+")[0]));
    return da.getFullYear() + "-" + (da.getMonth() + 1) + "-" + da.getDate() + " " + da.getHours() + ":" + da.getMinutes() + ":" + da.getSeconds();
}
//url获取参数
function GetQueryString(name) {
    var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
    if (result == null || result.length < 1) {
        return "";
    }
    return result[1];
}
